package com.he.hsdyc.start;

import com.he.hsdyc.config.ServerProperties;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.bean.menu.WxMenuButton;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Order(value=1)
public class WechatMenuCreator implements CommandLineRunner {

//    @Autowired
//    @Qualifier("wxMpService_user")
//    private WxMpService wxMpService_user;
//
//
//    @Autowired
//    @Qualifier("wxMpService_teacher")
//    private WxMpService wxMpService_teacher;
//
//    @Autowired
//    @Qualifier("wxMpService_parent")
//    private WxMpService wxMpService_parent;

    @Autowired
    @Qualifier("wxMpService_parent2")
    private WxMpService wxMpService_parent2;

    @Autowired
    private ServerProperties wechatProperties;

    @Override
    public void run(String... args) throws Exception {
//        String result1=this.createUserMenu();
//        System.out.println(result1);
//
//        String result2=this.createTeacherMenu();
//        System.out.println(result2);
//
//        String result3=this.createParentMenu();
//        System.out.println(result3);

        String result4=this.createParentMenu2();
        System.out.println(result4);
    }

//    /**
//     * 启动时创建菜单(用户)
//     */
//    private String createUserMenu(){
//
//        String result="";
//        WxMenu menu = new WxMenu();
//        WxMenuButton button1 = new WxMenuButton();
//        button1.setType(WxConsts.MenuButtonType.VIEW);
//        button1.setName("学校动态");
//        button1.setKey("home");
//        button1.setUrl(wechatProperties.getDomain()+"/hot/auth2User/hotindex");
//
//        WxMenuButton button2 = new WxMenuButton();
//        button2.setType(WxConsts.MenuButtonType.VIEW);
//        button2.setName("家校服务");
//        button2.setKey("service");
//        button2.setUrl(wechatProperties.getDomain()+"/service/auth2User/serviceindex");
//
//        WxMenuButton button3 = new WxMenuButton();
//        button3.setType(WxConsts.MenuButtonType.VIEW);
//        button3.setName("个人中心");
//        button3.setKey("user");
//        button3.setUrl(wechatProperties.getDomain()+"/user/auth2User/userindex");
//
//        menu.getButtons().add(button1);
//        menu.getButtons().add(button2);
//        menu.getButtons().add(button3);
//
//
//
//
//        try {
//            //创建菜单
//            result=this.wxMpService_user.getMenuService().menuCreate(menu);
//        } catch (WxErrorException e) {
//            e.printStackTrace();
//        }
//        return result;
//    }
//
//
//
//    /**
//     * 启动时创建菜单(教师)
//     */
//    private String createTeacherMenu(){
//
//        String result="";
//        WxMenu menu = new WxMenu();
//        WxMenuButton button1 = new WxMenuButton();
//        button1.setType(WxConsts.MenuButtonType.VIEW);
//        button1.setName("学校动态");
//        button1.setKey("teacherHot");
//        button1.setUrl(wechatProperties.getDomain()+"/teacherHot/auth2Teacher/hotIndex");
//
//        WxMenuButton button2 = new WxMenuButton();
//        button2.setType(WxConsts.MenuButtonType.VIEW);
//        button2.setName("家校服务");
//        button2.setKey("teaservice");
//        button2.setUrl(wechatProperties.getDomain()+"/teaservice/auth2Teacher/serviceindex");
//
//        WxMenuButton button3 = new WxMenuButton();
//        button3.setType(WxConsts.MenuButtonType.VIEW);
//        button3.setName("班课");
//        button3.setKey("teacherClass");
//        button3.setUrl(wechatProperties.getDomain()+"/teacherClass/auth2Teacher/classindex");
//
//        menu.getButtons().add(button1);
//        menu.getButtons().add(button2);
//        menu.getButtons().add(button3);
//
//
//
//
//        try {
//            //创建菜单
//            result=this.wxMpService_teacher.getMenuService().menuCreate(menu);
//        } catch (WxErrorException e) {
//            e.printStackTrace();
//        }
//        return result;
//    }
//
//
//    /**
//     * 启动时创建菜单(家长)
//     */
//    private String createParentMenu(){
//
//        String result="";
//        WxMenu menu = new WxMenu();
//        WxMenuButton button1 = new WxMenuButton();
//        button1.setType(WxConsts.MenuButtonType.VIEW);
//        button1.setName("学校动态");
//        button1.setKey("home");
//        button1.setUrl(wechatProperties.getDomain()+"/hot/auth2Parent/parentHotindex");
//
//        WxMenuButton button2 = new WxMenuButton();
//        button2.setType(WxConsts.MenuButtonType.VIEW);
//        button2.setName("家校服务");
//        button2.setKey("service");
//        button2.setUrl(wechatProperties.getDomain()+"/communication/auth2Parent/skip2Home");
//
//        WxMenuButton button3 = new WxMenuButton();
//        button3.setType(WxConsts.MenuButtonType.VIEW);
//        button3.setName("个人中心");
//        button3.setKey("work");
//        button3.setUrl(wechatProperties.getDomain()+"/center/auth2Parent/skipPersonalCenter");
//
//        menu.getButtons().add(button1);
//        menu.getButtons().add(button2);
//        menu.getButtons().add(button3);
//
//
//        try {
//            //创建菜单
//            result=this.wxMpService_parent.getMenuService().menuCreate(menu);
//        } catch (WxErrorException e) {
//            e.printStackTrace();
//        }
//        return result;
//    }
//


    /**
     * 启动时创建菜单(YES家长)
     */
    private String createParentMenu2(){



        String result="";
        WxMenu menu = new WxMenu();
        WxMenuButton button1 = new WxMenuButton();
        button1.setType(WxConsts.MenuButtonType.VIEW);
        button1.setName("后端");
        button1.setKey("home");
        button1.setUrl(wechatProperties.getDomain()+"/hot/auth2Parent2/parentHotindex");

        WxMenuButton button2 = new WxMenuButton();
        button2.setType(WxConsts.MenuButtonType.VIEW);
        button2.setName("前端");
        button2.setKey("service");
        button2.setUrl(wechatProperties.getDomain()+"/communication/auth2Parent2/skip2Home");

        WxMenuButton button3 = new WxMenuButton();
        button3.setType(WxConsts.MenuButtonType.VIEW);
        button3.setName("个人中心");
        button3.setKey("work");
        button3.setUrl("http://testing.aersaisi.top/");
//        button3.setUrl(wechatProperties.getDomain()+"/center/auth2Parent2/skipPersonalCenter");


        menu.getButtons().add(button1);
        menu.getButtons().add(button2);
        menu.getButtons().add(button3);


        try {
            //创建菜单
            result=this.wxMpService_parent2.getMenuService().menuCreate(menu);
        } catch (WxErrorException e) {
            e.printStackTrace();
        }
        return result;
    }


}
